<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
                xmlns:lxslt="http://xml.apache.org/xslt"
                xmlns:redirect="http://xml.apache.org/xalan/redirect"
                extension-element-prefixes="redirect">

    <xsl:template match="checkstyle" mode="summary">
        <html>
            <head>
                <link rel="stylesheet" type="text/css" href="stylesheet.css"/>
            </head>
            <body>
                <!-- page header -->
                <xsl:call-template name="pageHeader"/>

                <!-- Summary part -->
                <xsl:apply-templates select="." mode="summary.checkstyle"/>
                <hr size="1" width="100%" align="left"/>

                <!-- File list part -->
                <xsl:apply-templates select="." mode="summary.type"/>
                <hr size="1" width="100%" align="left"/>

                <xsl:apply-templates select="." mode="summary.folder"/>

            </body>
        </html>
    </xsl:template>

    <xsl:template match="checkstyle" mode="summary.checkstyle">
        <h3>Summary</h3>
        <xsl:variable name="typeCount" select="count(//checktype)"/>
        <xsl:variable name="fileCount" select="count(//file)"/>
        <xsl:variable name="errorCount" select="count(//error)"/>
        <table class="log" border="0" cellpadding="5" cellspacing="2" width="100%">
            <tr>
                <th>Type</th>
                <th>Files</th>
                <th>Errors</th>
            </tr>
            <tr>
                <xsl:call-template name="alternated-row"/>
                <td>
                    <xsl:value-of select="$typeCount"/>
                </td>
                <td>
                    <xsl:value-of select="$fileCount"/>
                </td>
                <td>
                    <xsl:value-of select="$errorCount"/>
                </td>
            </tr>
        </table>
    </xsl:template>

    <xsl:template match="checkstyle" mode="summary.type">
        <h3>Check Types</h3>
        <table class="log" border="0" cellpadding="5" cellspacing="2" width="100%">
            <xsl:apply-templates select="checktype" mode="summary.type">
                <xsl:sort select="@type"/>
            </xsl:apply-templates>
        </table>
    </xsl:template>

    <xsl:template match="checktype" mode="summary.type">
        <xsl:variable name="first">
            <xsl:call-template name="isfirst">
                <xsl:with-param name="name" select="@type"/>
            </xsl:call-template>
        </xsl:variable>
        <xsl:variable name="type" select="@type"/>

        <xsl:if test="$first = 'true'">
            <tr>
                <xsl:call-template name="alternated-row"/>
                <td nowrap="nowrap">
                    Type
                    <b>
                        <xsl:value-of select="$type"/>
                    </b>
                    has found out
                    <b>
                        <xsl:value-of select="count(../checktype[@type = $type]//file)"/>
                        files
                    </b>
                    contains
                    <b>
                        <xsl:value-of select="count(../checktype[@type = $type]//error)"/>
                        errors
                    </b>
                    . Check
                    <a target="mainFrame">
                        <xsl:attribute name="href">
                            <xsl:text>files/</xsl:text>
                            <xsl:value-of select="$type"/>
                            <xsl:text>.html</xsl:text>
                        </xsl:attribute>
                        Type Summary
                    </a>
                    for details.
                </td>
            </tr>
        </xsl:if>
    </xsl:template>

    <xsl:template match="checkstyle" mode="summary.folder">
        <h3>Folders</h3>
        <table class="log" border="0" cellpadding="5" cellspacing="2" width="100%">
            <tr>
                <th>Path</th>
                <th>Files</th>
                <th>Errors</th>
            </tr>
            <xsl:apply-templates select="checktype/folder" mode="summary.folder">
                <xsl:sort select="@name"/>
                <xsl:with-param name="parent-folder" select="''"/>
                <xsl:with-param name="parent-name" select="''"/>
            </xsl:apply-templates>
        </table>
    </xsl:template>

    <xsl:template match="folder" mode="summary.folder">
        <xsl:param name="parent-folder"/>
        <xsl:param name="parent-name"/>
        <xsl:variable name="name" select="@name"/>
        <xsl:variable name="fileCount" select="count(./file)"/>
        <xsl:variable name="errorCount" select="count(./file/error)"/>

        <xsl:variable name="new-name">
            <xsl:call-template name="from-dos">
                <xsl:with-param name="path" select="@name"/>
            </xsl:call-template>
        </xsl:variable>

        <xsl:if test="$fileCount > 0">
            <tr>
                <xsl:call-template name="alternated-row"/>
                <td nowrap="nowrap">
                    <a target="mainFrame">
                        <xsl:attribute name="href">
                            <xsl:text>files/</xsl:text>
                            <xsl:value-of select="concat($parent-folder,$new-name)"/>
                            <xsl:text>summary.html</xsl:text>
                        </xsl:attribute>
                        <xsl:value-of select="concat($parent-name, @name)"/>
                    </a>
                </td>
                <td>
                    <xsl:value-of select="count(../folder[@name = $name]//file)"/>
                </td>
                <td>
                    <xsl:value-of select="count(../folder[@name = $name]//error)"/>
                </td>
            </tr>
        </xsl:if>

        <xsl:apply-templates select="./folder" mode="summary.folder">
            <xsl:sort select="@name"/>
            <xsl:with-param name="parent-folder" select="concat($parent-folder,$new-name)"/>
            <xsl:with-param name="parent-name" select="concat($parent-name, @name)"/>
        </xsl:apply-templates>
    </xsl:template>

</xsl:stylesheet>